var util = require('util');
var EventEmitter = require('events').EventEmitter;

var User = function (opts) {
    this.uid = opts.uid;
    this.real_open_id = opts.real_open_id;
    this.invite_id = opts.invite_id;
    this.password = opts.password;
    this.parent_id = opts.parent_id;
    this.union_id = opts.union_id;
    this.nickname = opts.nickname;
    this.avatar = opts.avatar;
    this.gender = opts.gender;
    this.city = opts.city;
    this.province = opts.province;
    this.balance = opts.balance;
    this.oil = opts.oil;
    this.jewel = opts.jewel;
    this.coins = opts.coins;
    this.title = opts.title;
    this.title_logo = opts.title_logo;
    this.last_login_time = opts.last_login_time;
    this.last_logout_time = opts.last_logout_time;
    this.is_effect_user = opts.is_effect_user;
    this.current_level = opts.current_level;

    this.apprentice_num = opts.apprentice_num;
    this.disciple_num = opts.disciple_num;
    this.apprentice_oil = opts.apprentice_oil;
    this.disciple_oil = opts.disciple_oil;
    this.apprentice_oil_today = opts.apprentice_oil_today;
    this.disciple_oil_today = opts.disciple_oil_today;
    this.video_num = opts.video_num;
    this.ip = opts.ip;
    this.share_poster = opts.share_poster;

    this.fx_level = opts.fx_level;
    this.first_withdraw = opts.first_withdraw;
    this.second_withdraw = opts.second_withdraw;
    this.red_packet_level = opts.red_packet_level;
    this.nextRedPacketInfo = opts.nextRedPacketInfo;
    this.red_packet_income = opts.red_packet_income;
    this.ordinary_treasure_num = opts.ordinary_treasure_num;
    this.superior_treasure_num = opts.superior_treasure_num;
    this.gmt_create = opts.gmt_create;
    this.gmt_modified = opts.gmt_modified;
    this.levelInfo = opts.levelInfo;
    this.gmt_modified = opts.gmt_modified;
    this.openChestInfo = opts.openChestInfo;
    this.reward_jewel = opts.reward_jewel;

    this.total_income = opts.total_income;
    this.yesterday_income = opts.yesterday_income;
    this.luck_draw_num = opts.luck_draw_num;
    this.today_money = opts.today_money;
    this.share_poster = opts.share_poster;
    this.chest_pool = opts.chest_pool;
    this.offline_reward = opts.offline_reward;
    this.first_open_chest = opts.first_open_chest;
    this.double_time = opts.double_time;
    this.begin_double = opts.begin_double;
    this.is_first_chest = opts.is_first_chest;
    this.poster_list = opts.poster_list;
    this.join_plan = opts.join_plan;
    this.nowCountDownInfo = opts.nowCountDownInfo;
    this.total_oil = opts.total_oil;
    this.depth_level = opts.depth_level;
    this.quality_level = opts.quality_level;
    this.spreed_level = opts.spreed_level;
    this.depth = opts.depth;
    this.welfare = opts.welfare;
    this.welfare_oil = opts.welfare_oil;
    this.total_video = opts.total_video;

    this.new_player_prize = opts.new_player_prize;
    this.contact_info = opts.contact_info;    //用户联系方式
    this.current_level = opts.current_level;
};

User.prototype.strip = function () {
    return {
        uid: this.uid,
        invite_id: this.invite_id,
        password: this.password,
        parent_id: this.parent_id,
        union_id: this.union_id,
        nickname: this.nickname,
        avatar: this.avatar,
        gender: this.gender,
        city: this.city,
        province: this.province,
        balance: this.balance,
        oil: this.oil,
        jewel: this.jewel,
        coins: this.coins,
        title: this.title,
        title_logo: this.title_logo,
        last_login_time: this.last_login_time,
        last_logout_time: this.last_logout_time,
        is_effect_user: this.is_effect_user,
        current_level: this.current_level,
        apprentice_num: this.apprentice_num,
        disciple_num: this.disciple_num,
        fx_level: this.fx_level,
        first_withdraw: this.first_withdraw,
        second_withdraw: this.second_withdraw,
        red_packet_level: this.red_packet_level,
        nextRedPacketInfo: this.nextRedPacketInfo,
        red_packet_income: this.red_packet_income,
        ordinary_treasure_num: this.ordinary_treasure_num,
        superior_treasure_num: this.superior_treasure_num,
        gmt_create: this.gmt_create,
        gmt_modified: this.gmt_modified,
        levelInfo: this.levelInfo,
        openChestInfo: this.openChestInfo,
        reward_jewel: this.reward_jewel,
        ip: this.ip,
        total_income: this.total_income,
        yesterday_income: this.yesterday_income,
        video_num: this.video_num,
        luck_draw_num: this.luck_draw_num,
        share_poster: this.share_poster,
        chest_pool: this.chest_pool,
        offline_reward: this.offline_reward,
        first_open_chest: this.first_open_chest,
        double_time: this.double_time,
        begin_double: this.begin_double,
        is_first_chest: this.is_first_chest,
        poster_list: this.poster_list,
        join_plan: this.join_plan,
        exchange: this.exchange,
        total_oil: this.total_oil,
        depth_level: this.depth_level,
        quality_level: this.quality_level,
        spreed_level: this.spreed_level,
        depth: this.depth,
        ownOpenBox: this.ownOpenBox,    //已拥有宝箱
        waitOpenBox: this.waitOpenBox,    //待领取宝箱
        upgrade: this.upgrade,    //升级系统
        share_poster: this.share_poster, //分享海报
        welfare: this.welfare, //福利时刻
        welfare_oil: this.welfare_oil,
        total_video: this.total_video, //看视频总次数

        new_player_prize: this.new_player_prize,//新手奖励
        signIn: this.signIn,    //签到信息
        luckDraw: this.luckDraw,    //幸运抽奖
        give_box_log: this.give_box_log,    //宝箱获取记录
        open_box_log: this.open_box_log,    //宝箱打开记录
        contact_info: this.contact_info,    //用户联系方式
        exchangeEssence: this.exchangeEssence,    //石油精华交易所
        current_level: this.current_level, //当前矿层等级
    };
};

util.inherits(User, EventEmitter);

User.prototype.immediatelySave = function () {
    this.emit('updateUser');
};
User.prototype.chestSave = function () {
    this.emit('chestSave');
};
User.prototype.exchangeSave = function () {
    this.emit('exchangeSave');
};
User.prototype.upgradeSave = function () {
    this.emit('upgradeSave');
};
User.prototype.signInSave = function () {
    this.emit('signInSave');
};
User.prototype.luckDrawSave = function () {
    this.emit('luckDrawSave');
};
User.prototype.syncBox = function () {
    this.emit('syncBox');
};
User.prototype.exchangeEssenceSave = function () {
    this.emit('exchangeEssenceSave');
};
User.prototype.updateMap = function () {
    this.emit('updateMap');
};

/**
 * 保存用户的矿层信息
 */
User.prototype.syncMap = function () {
    console.log('emit syncMap')
    this.emit('syncMap');
}

module.exports = User;
